package org.ansel.webnodb.demo.controller;

import org.ansel.webnodb.demo.beans.BaseResponse;
import org.ansel.webnodb.demo.service.IpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/api")
public class IpRestController {
	@Autowired
	private IpService ipService;
	@Deprecated
	@GetMapping(value = "/ip")
	public BaseResponse<String> ip(){
		BaseResponse<String> res=new BaseResponse<String>(true, "OK", "");
		String serveip=ipService.getPublicIp();
		res.setData(serveip);
		if("".equals(serveip)) {
			res.setSuccess(false);
			res.setMsg("get Serve ip failed.");
		}
		return res;
	}
	
	/** 获取翻墙免费节点。返回base64长文本。
	 * @param usonly 筛选北美节点。1是0否。
	 * @return
	 */
	@RequestMapping(value = "/getfreenodes", method = RequestMethod.GET)
	public String getfreenodes(String usonly){
		String res = "";
		res = ipService.getFreeNodes(usonly);
		return res;
	}
}
